﻿var ListContainer = new Array();
var ItemCardCount = 20;
var FocusItemCard;
var OpenMode = false;
var AutoFresh = false;
var OpenPlace = false;
var freshItemCard = false;
var PageChangeHint = false;
var ItemCardDisplay = new Array();
var correlativeCode = null;

var Class_ItemCardModelNew = function (_code, _meid, _title, _describe, _ifrcode, _index, _html, _url, _state, _width, _type, _nextCard, _priorCard, _flag) {
    this.ItemCardCode = _code;
    this.ItemModelCode = _meid || null;
    this.ItemModelName = _title || null;
    this.ItemModelDescribe = _describe;
    this.ItemIframeCode = _ifrcode;
    this.ItemIndex = _index;
    this.ItemHtml = _html || null;
    this.ItemUrl = _url;
    this.ItemState = _state || null;
    this.ItemType = _type || 0;
    this.NextCardItemCode = _nextCard || null;
    this.PriorCardItemCode = _priorCard || null;
    this.ItemCardChange = false;
    this.ItemControlCode = _flag || null;
    this.FormatModelName = function () {
        return this.ItemModelName.length > 8 ? this.ItemModelName.substring(0, 8) + ".." : this.ItemModelName;
    }
};

var Class_ItemCard_ListNew = {
    Add: function (_objitem) {
        if (this.GetCount() == 0) {
            _objitem.PriorCardItemCode = null; ListContainer.push(_objitem);
            return;
        };
        var model = ListContainer[ListContainer.length - 1];
        model.NextCardItemCode = _objitem.ItemCardCode;
        _objitem.PriorCardItemCode = model.ItemCardCode;
        ListContainer.push(_objitem);
    },
    Delete: function (flag) {
        try {
            if (flag)
                ListContainer.splice(0, ListContainer.length);
            else
                ListContainer.splice(1, ListContainer.length - 1);
            return true;
        } catch (e) {
            return false;
        }
    },
    DeleteOfByCardCode: function (_cardcode) {
        if (typeof (_cardcode) == "undefinde" || _cardcode == null || _cardcode == "")
            return true;
        var pItemCard = null,
            nItemCard = null,
            itemCard = null;
        for (var index = 0; index < ListContainer.length; index++) {
            if (ListContainer[index].ItemCardCode == _cardcode) {
                itemCard = ListContainer[index];
                if (itemCard.NextCardItemCode == null) {
                    pItemCard = this.GetOfByItemCardCode(itemCard.PriorCardItemCode);
                    pItemCard.NextCardItemCode = itemCard = null;
                } else {
                    pItemCard = this.GetOfByItemCardCode(itemCard.PriorCardItemCode);
                    nItemCard = this.GetOfByItemCardCode(itemCard.NextCardItemCode);
                    pItemCard.NextCardItemCode = nItemCard.ItemCardCode;
                    nItemCard.PriorCardItemCode = pItemCard.ItemCardCode;
                };
                ListContainer.splice(index, 1);
                nItemCard = pItemCard = itemCard = null;
                delete pItemCard;
                delete nItemCard;
                delete itemCard;
                return true;
            }
        };
        return false;
    },
    GetCount: function () {
        return ListContainer.length;
    },
    GetOfByModelCode: function (meid) {
        if (this.GetObjectEmpty(meid))
            return null;
        for (var index = 0; index < ListContainer.length; index++) {
            if (ListContainer[index].ItemModelCode == meid)
                return ListContainer[index];
        };
        return null;
    },
    GetObjectEmpty: function (obj) {
        if (obj == null || typeof (obj) == "undefined")
            return true;
        return false;
    },
    GetOfByItemCardCode: function (code) {
        if (this.GetObjectEmpty(code))
            return null;
        for (var index = 0; index < ListContainer.length; index++) {
            if (ListContainer[index].ItemCardCode == code)
                return ListContainer[index];
        };
        return null;
    },
    GetOfByModelName: function (name) {
        if (this.GetObjectEmpty(name))
            return null;
        for (var index = 0; index < ListContainer.length; index++) {
            if (ListContainer[index].ItemModelName == name)
                return ListContainer[index];
        };
        return null;
    },
    GetItemCode: function () {
        return ListContainer.length == 0 ? 0 : parseInt(ListContainer[ListContainer.length - 1].ItemIndex) + 1;
    },
    GetPriorCardItemCode: function () {
        return ListContainer.length == 0 ? null : ListContainer[ListContainer.length - 1].ItemCardCode;
    },
    GetFocus: function () {
        if (FocusItemCard >= this.GetCount())
            return null;
        return ListContainer[FocusItemCard];
    },
    SetFocus: function (itemCard) {
        if (itemCard == null) return;
        for (var index = 0; index < ListContainer.length; index++) {
            if (ListContainer[index].ItemCardCode == itemCard.ItemCardCode) {
                FocusItemCard = index;
                return true;
            }
        };
        return false;
    },
    GetOfByItemCardIndex: function (itemCardIndex) {
        return ListContainer[itemCardIndex];
    }
};

var Class_ItemCard_OprnNew = {
    CloseAllItemCard: function () {
        var count = Class_ItemCard_ListNew.GetCount();
        if (count <= 1)
            return;
        var tmp = window.confirm("确定要关闭所有选项卡吗?");
        if (!tmp)
            return;
        var flag = false;
        for (var index = 0; index < count; index++) {
            var model = Class_ItemCard_ListNew.GetOfByItemCardIndex(index);
            if (model.ItemCardCode == "Card_0")
                continue;
            try {
                var itemCard = this.Object$(model.ItemCardCode);
                if (itemCard) {
                    itemCard.parentNode.removeChild(itemCard);
                    itemCard = null;
                    delete itemCard;
                };
                var itemIframe = this.Object$(model.ItemIframeCode);
                itemIframe.src = "javascript:false;"; itemIframe.parentNode.removeChild(itemIframe);
                itemIframe.removeNode(true);
                itemIframe = null;
                delete itemIframe;
                flag = true;
            } catch (e) {
                flag = false;
            }
        };

        try {
            Class_ItemCard_ListNew.Delete(false);
            var myDCI = Class_ItemCard_ListNew.GetOfByItemCardCode("Card_0");
            var _obj = this.Object$("Card_0");
            _obj.className = "comtabsl";
            _obj.innerHTML = "<span class='comtabsr'>" + _obj.innerText + "</span>";
            this.Object$(myDCI.ItemIframeCode).style.display = "";
            Class_ItemCard_ListNew.SetFocus(myDCI);
            var cardfast = this.Object$("card_list").style.display = "none";
            ItemCardDisplay = null;
            ItemCardDisplay = new Array();
        } catch (e) { }
    },
    Run_ItemCard: function (meid, mename, meurl, state, flag) {
        Get_Loading();
        if (OpenMode) {
            if (ItemCardCount > Class_ItemCard_ListNew.GetCount())
                this.Create_ItemCard(meid, mename, meurl, state);
            else
                this.OverlayItemCard(meid, mename, meurl, state);
        } else {
            if (flag == 1)
                model = Class_ItemCard_ListNew.GetFocus();
            var modelSearch = meid != null ? Class_ItemCard_ListNew.GetOfByModelCode(meid) : Class_ItemCard_ListNew.GetOfByModelName(mename);
            if (modelSearch == null) {
                if (ItemCardCount > Class_ItemCard_ListNew.GetCount())
                    this.Create_ItemCard(meid, mename, meurl, state);
                else
                    this.AfreshItemCard(meid, mename, meurl, state);
            } else
                this.OverlayItemCard(meid, mename, meurl, state);
            if (flag != 1)
                return;
            var modelNew = meid != null ? Class_ItemCard_ListNew.GetOfByModelCode(meid) : Class_ItemCard_ListNew.GetOfByModelName(mename);
            modelNew.ItemControlCode = model.ItemCardCode;
            model.ItemControlCode = model.ItemCardCode;
        }
    },
    AfreshItemCard: function (meid, mename, meurl, state) {
        var model = Class_ItemCard_ListNew.GetOfByItemCardIndex(1);
        model.ItemModelCode = meid;
        model.ItemModelName = mename;
        model.ItemModelDescribe = mename;
        freshItemCard = true;
        this.SelectItemCard(model);
    },
    OverlayItemCard: function (meid, mename, meurl, state) {
        var model = meid != null ? Class_ItemCard_ListNew.GetOfByModelCode(meid) : Class_ItemCard_ListNew.GetOfByModelName(mename);
        model.ItemModelName = mename; model.ItemState = state;
        model.ItemUrl = meurl;
        freshItemCard = true;
        var obj = this.Object$(model.ItemCardCode);
        this.SelectItemCard(obj);
    },
    Create_ItemCard: function (id, name, url, state) {
        var md = new Class_ItemCardModelNew();
        code = Class_ItemCard_ListNew.GetItemCode();
        md.ItemCardCode = "Card_" + code;
        md.ItemModelCode = id;
        md.ItemModelName = name;
        md.ItemIframeCode = "Card_ifr_" + code;
        md.ItemIndex = code;
        md.ItemUrl = url;
        md.ItemType = 0;
        md.ItemState = state;
        md.ItemModelDescribe = name;
        md.ItemCardChange = false;
        this.CreateItemFrame(md);
        var iCard = this.CreateItemCard(md);
        Class_ItemCard_ListNew.Add(md);
        if (Class_ItemCard_ListNew.GetCount() > 1)
            this.SelectItemCard(iCard);
    },
    RefreshItemCard: function (iCard) {
        try {
            var obj = this.Object$(iCard.ItemIframeCode);
            try {
                obj.src = "javascript:false;"; obj.parentNode.removeChild(obj);
            } catch (e) { };
            this.CreateItemFrame(iCard);
        } catch (e) { };
        freshItemCard = false;
    },
    SelectItemCard: function (iCard) {
        var iCard = Class_ItemCard_ListNew.GetOfByItemCardCode(iCard.id);

        if (iCard == null)
            return;
        var oldfocus = Class_ItemCard_ListNew.GetFocus();
        if (iCard == oldfocus) {
            this.RefreshItemCard(iCard);
            return;
        };
        var objOldFocus = this.Object$(oldfocus.ItemCardCode);
        var title = objOldFocus.title;
        var caption = objOldFocus.innerText;
        if (objOldFocus.onclick == null) {
            this.Object$(oldfocus.ItemCardCode).outerHTML = "<span class='comtabl' id=" + oldfocus.ItemCardCode + " title='" + title + "' onclick='top.Class_ItemCard_OprnNew.SelectItemCard(this);'></span>";
        };
        this.Object$(oldfocus.ItemCardCode).className = "comtabl";
        this.Object$(oldfocus.ItemCardCode).innerHTML = "<span class='comtabr'>" + caption + "</span>";

        try {
            if (iCard.ItemType == 0) {
                this.Object$(iCard.ItemCardCode).className = "comtabsl";
                if (iCard.ItemIndex != 0) {
                    this.Object$(iCard.ItemCardCode).onclick = null;
                    this.Object$(iCard.ItemCardCode).innerHTML = "<span class='comtabsr'><img id=z" + iCard.ItemCardCode + " title='点击弹出该窗口' style='cursor: pointer' onclick=\"" + this.OpenMaxWindow(iCard) + "\" src='../App_Themes/" + top.SystemSkinName + "/Images/zoom.gif' align='absmiddle'>" + this.Object$(iCard.ItemCardCode).innerText + " " + "<img id=m'" + iCard.ItemCardCode + "' style='cursor: pointer;' onmouseout='mouseOut(id)'; onmouseover='mouseOver(id)' src='../App_Themes/" + top.SystemSkinName + "/Images/button_close_close.gif' onclick='Class_ItemCard_OprnNew.Close_ItemCard();' title='关闭选项卡' align='absmiddle'></span>";
                } else
                    this.Object$(iCard.ItemCardCode).innerHTML = "<span class='comtabsr'>" + this.Object$(iCard.ItemCardCode).innerText + "</span>";
            } else {
                this.Object$("Item_Card").innerHTML += "<span class='comtabsl' id='" + iCard.ItemCardCode + "' onclick='Class_ItemCard_OprnNew.SelectItemCard(this);' title='" + iCard.ItemModelDescribe + "'><span class='comtabsr'>" + iCard.FormatModelName() + "<img id=m'" + iCard.ItemCardCode + "' src='../App_Themes/" + top.SystemSkinName + "/Images/button_close_close.gif' onclick='Class_ItemCard_OprnNew.Close_ItemCard();' title='关闭选项卡' align='absmiddle'></span></span>";
                this.Object$(iCard.ItemCardCode).innerHTML = "<span class='comtabsr'><img id=z" + iCard.ItemCardCode + " title='点击弹出该窗口' style='CURSOR: pointer' onclick=\"" + this.OpenMaxWindow(iCard) + "\" src='../App_Themes/" + top.SystemSkinName + "/Images/zoom.gif' align='absmiddle'>" + iCard.FormatModelName() + " " + "<img id=m'" + iCard.ItemCardCode + "' style='cursor: pointer;' onmouseout='mouseOut(id)'; onmouseover='mouseOver(id)' src='../App_Themes/" + top.SystemSkinName + "/Images/button_close_close.gif' onclick='Class_ItemCard_OprnNew.Close_ItemCard();' title='关闭选项卡' align='absmiddle'></span>";
                iCard.ItemType = 0;
            };

            this.Object$(iCard.ItemIframeCode).style.display = "";
        } catch (e) {
        }
        this.Object$(oldfocus.ItemIframeCode).style.display = "none";
        Class_ItemCard_ListNew.SetFocus(iCard);
        this.StyleItemCard();
        if (iCard == null) {
            return;
        }

        if (freshItemCard || iCard.ItemCardCode == iCard.ItemControlCode)
            this.RefreshItemCard(iCard);
    },
    OpenMaxWindow: function (itemCard) {
        if (window.attachEvent) {
            return "var win = top.open('" + itemCard.ItemUrl + "','_blank','scrollbars=no,top=0,left=0,status=no,toolbar=no,location=no,menubar=no,resizable=yes,width='+screen.width+',height='+screen.height);" + "win.attachEvent('onload', function(){win.resizeTo(screen.width - 1, screen.height - 1);win.resizeTo(screen.width, screen.height);});";
        } else if (window.addEventListener) {
            return "var win = top.open('" + itemCard.ItemUrl + "','_blank','scrollbars=no,top=0,left=0,status=no,toolbar=no,location=no,menubar=no,resizable=yes,width='+screen.width+',height='+screen.height);" + "win.addEventListener('load', function(){win.resizeTo(screen.width - 1, screen.height - 1);win.resizeTo(screen.width, screen.height);},false);";
        }

        return "var win = top.open('" + itemCard.ItemUrl + "','_blank','scrollbars=no,top=0,left=0,status=no,toolbar=no,location=no,menubar=no,resizable=yes,width='+screen.width+',height='+screen.height);" + "win.attachEvent('onload', function(){win.resizeTo(screen.width - 1, screen.height - 1);win.resizeTo(screen.width, screen.height);});";
    },
    CreateItemCard: function (iCard) {
        this.Object$("Item_Card").innerHTML += "<span class='comtabsl' id='" + iCard.ItemCardCode + "'onclick='top.Class_ItemCard_OprnNew.SelectItemCard(this);'title='" + iCard.ItemModelDescribe + "'></span>";
        var newICard = this.Object$(iCard.ItemCardCode);
        var newIName = document.createElement("span");
        if (window.attachEvent) {
            newIName.setAttribute("className", "comtabsr");
        } else if (window.addEventListener) {
            newIName.setAttribute("class", "comtabsr");
        }
        newIName.appendChild(document.createTextNode(iCard.FormatModelName()));
        newICard.appendChild(newIName);
        return newICard;
    },
    CreateItemFrame: function (itemCard) {
        var nIframe = document.createElement("iframe");
        nIframe.setAttribute("id", itemCard.ItemIframeCode);
        nIframe.setAttribute("src", itemCard.ItemUrl);
        nIframe.setAttribute("frameBorder", 0);
        nIframe.setAttribute("scrolling", "none");
        this.Object$("Item_Card_Iframe").appendChild(nIframe);
        nIframe.style.width = "100%";
        nIframe.style.height = "100%";
        nIframe.style.position = "relative";
        nIframe.style.paddingLeft = "0px";
        nIframe.style.paddingRight = "0px";
        nIframe.style.paddingBottom = "0px";
        nIframe.style.border = "solid 1px #AABFD3";

        if (nIframe.attachEvent) {
            nIframe.attachEvent("onload", function (e) {
                e = window.event || e;
                Class_ItemCard_OprnNew.IframeLoad(e);
            });
        } else if (nIframe.addEventListener) {
            nIframe.addEventListener("load", function (e) {
                e = window.event || e;
                Class_ItemCard_OprnNew.IframeLoad(e);
            }, false);
        }

        return nIframe;
    },
    IframeLoad: function (obj) {
        //if (obj.srcElement == null)
        //return;
        if (PageChangeHint) {
            var flag = false;
            var childWindow = obj.srcElement.contentWindow.window.document;
            var btnlist = childWindow.getElementsByTagName("input");
            for (var index = 0; index < btnlist.length; index++) {
                if (btnlist[index].type == "submit") {
                    if (btnlist[index].ACTION_ID == "4") {
                        flag = true;
                        break;
                    }
                }
            };
            if (flag) {
                obj.srcElement.contentWindow.window.document.onclick = function () {
                    if (this.activeElement.isContentEditable) {
                        var control = this.getElementById(this.activeElement.id);

                        if (control.attachEvent) {
                            control.attachEvent("onchange", function (e) {
                                e = window.event || e; ChangeValue(e);
                            });
                        } else if (control.addEventListener) {
                            control.addEventListener("change", function (e) {
                                e = window.event || e; ChangeValue(e);
                            }, false);
                        }
                    }
                }
            };
            function ChangeValue(e) {
                var md = top.Class_ItemCard_ListNew.GetFocus();
                md.ItemCardChange = true;
            }
        };
        top.Set_UnLoading();
    },
    Close_AjaxWeb: function () {
        setTimeout("Class_ItemCard_OprnNew.Close_ItemCard()", 100);
    },
    Close_ItemCard: function () {
        var md = Class_ItemCard_ListNew.GetFocus();
        //var md = _option.ItemCard;
        if (md.ItemControlCode != "") {
            var refItemCard = Class_ItemCard_ListNew.GetOfByItemCardCode(md.ItemControlCode);
            this.RefreshItemCard(refItemCard);
        }; this.Close(md);
    },
    Close: function (itemCard) {
        if (itemCard.ItemCardChange && PageChangeHint) {
            var tmp = window.confirm("页面已被修改，请先保存?");
            if (tmp) {
                event.returnValue = false; return;
            }
        };
        var obj = this.Object$(itemCard.ItemIframeCode);
        try {
            obj.src = "javascript:false;";
            this.DeleteNode(obj);
        } catch (e) { };
        obj = this.Object$(itemCard.ItemCardCode);
        try {
            obj.parentNode.removeChild(obj);
        }
        catch (e) { };
        var pItemCardCode = itemCard.PriorCardItemCode;
        Class_ItemCard_ListNew.DeleteOfByCardCode(itemCard.ItemCardCode);
        var pItemCard = Class_ItemCard_ListNew.GetOfByItemCardCode(pItemCardCode);
        if (pItemCard.ItemType == 0)
            obj = this.Object$(pItemCard.ItemCardCode);
        else {
            for (var index = 0; index < ItemCardDisplay.length; index++) {
                if (ItemCardDisplay[index].id == pItemCard.ItemCardCode) {
                    obj = ItemCardDisplay[index];
                    ItemCardDisplay.slice(index, 1);
                    break;
                }
            }
        };
        obj.className = "comtabsl";
        if (pItemCard.ItemCardCode != "Card_0") {
            if (pItemCard.ItemType == 0)
                obj.innerHTML = "<span class='comtabsr' title='" + pItemCard.ItemModelName + "'><img id=z" + pItemCard.ItemCardCode + " title='点击弹出该窗口' style='CURSOR: pointer' onclick=\"" + this.OpenMaxWindow(pItemCard) + "\" src='../App_Themes/" + top.SystemSkinName + "/Images/zoom.gif' align='absmiddle'>" + obj.innerText + " " + "<img id=m'" + pItemCard.ItemCardCode + "' style='cursor: pointer;'onmouseout='mouseOut(id)'; onmouseover='mouseOver(id)' src='../App_Themes/" + top.SystemSkinName + "/Images/button_close_close.gif' onclick='Class_ItemCard_OprnNew.Close_ItemCard();' title='关闭选项卡' align='absmiddle'></span>";
            else {
                this.DeleteNode(obj);
                pItemCard.ItemType = 0;
                this.Object$("Item_Card").innerHTML += "<span class='comtabsl' id='" + pItemCard.ItemCardCode + "' onclick='Class_ItemCard_OprnNew.SelectItemCard(this);' title='" + pItemCard.ItemModelDescribe + "'><span class='comtabsr'>" + pItemCard.FormatModelName() + "<img id=m'" + pItemCard.ItemCardCode + "' src='../App_Themes/" + top.SystemSkinName + "/Images/button_close_close.gif' onclick='Class_ItemCard_OprnNew.Close_ItemCard();' title='关闭选项卡' align='absmiddle'></span></span>";
                this.Object$(pItemCard.ItemCardCode).innerHTML = "<span class='comtabsr'><img id=z" + pItemCard.ItemCardCode + " title='点击弹出该窗口' style='CURSOR: pointer' onclick=\"" + this.OpenMaxWindow(pItemCard) + "\" src='../App_Themes/" + top.SystemSkinName + "/Images/zoom.gif' align='absmiddle'>" + pItemCard.FormatModelName() + " " + "<img id=m'" + pItemCard.ItemCardCode + "' style='cursor: pointer;' onmouseout='mouseOut(id)'; onmouseover='mouseOver(id)' src='../App_Themes/" + top.SystemSkinName + "/Images/button_close_close.gif' onclick='Class_ItemCard_OprnNew.Close_ItemCard();' title='关闭选项卡' align='absmiddle'></span>";
            }
        } else
            obj.innerHTML = "<span class='comtabsr'>" + obj.innerText + "</span>"; Class_ItemCard_ListNew.SetFocus(pItemCard);
        this.Object$(pItemCard.ItemIframeCode).style.display = "";
        this.StyleItemCard();
    },
    DeleteNode: function (obj) {
        try {
            obj.parentNode.removeChild(obj);
            obj = null;
            delete obj;
        } catch (e) { }
    },
    Object$: function (objstr) {
        var obj = document.getElementById(objstr);
        if (obj != null)
            return obj
    },
    StyleItemCard: function () {
        this.TypeItemCard();
        if (!Class_ItemCard_OprnNew._InitResizeListener) {
            Class_ItemCard_OprnNew._InitResizeListener = true;

            if (window.attachEvent) {
                window.attachEvent("onresize", function () {
                    if (!Class_ItemCard_OprnNew._IsResizeEnd) {
                        Class_ItemCard_OprnNew._IsResizeEnd = true;
                        Class_ItemCard_OprnNew.TypeItemCard();
                    } else
                        Class_ItemCard_OprnNew._IsResizeEnd = false;
                });
            } else if (window.addEventListener) {
                window.addEventListener("resize", function () {
                    if (!Class_ItemCard_OprnNew._IsResizeEnd) {
                        Class_ItemCard_OprnNew._IsResizeEnd = true;
                        Class_ItemCard_OprnNew.TypeItemCard();
                    } else
                        Class_ItemCard_OprnNew._IsResizeEnd = false;
                }, false);
            }
        }
    },
    CardListOnClick: function (flag) {
        var len = ItemCardDisplay.length;
        var obj = ItemCardDisplay[len - 1];
        var model = Class_ItemCard_ListNew.GetOfByItemCardCode(obj.id);
        if (model == Class_ItemCard_ListNew.GetFocus()) {
            obj = ListContainer[len - 2];
            ItemCardDisplay.splice(len - 2, 1);
        } else
            ItemCardDisplay.splice(len - 1, 1);
        Class_ItemCard_OprnNew.SelectItemCard(obj);
    },
    TypeItemCard: function () {
        try {
            var _width = this.Object$("Item_Card").parentElement.offsetWidth;
            var _itemcount = this.Object$("Item_Card").offsetWidth;
            var card_list = this.Object$("card_list");
            if (_itemcount + 50 - _width >= 0) {
                card_list.style.display = "";
                var _index = 0;
                do {
                    _index += 1;
                    var _objid = document.all.Item_Card.childNodes[_index].id;
                    var model = Class_ItemCard_ListNew.GetOfByItemCardCode(_objid);
                    if (model == Class_ItemCard_ListNew.GetFocus())
                        continue;
                    try {
                        ItemCardDisplay.push(this.Object$(model.ItemCardCode));
                        this.Object$(model.ItemCardCode).parentNode.removeChild(this.Object$(model.ItemCardCode));
                    } catch (e) { };
                    model.ItemType = 1;
                }
                while (this.Object$("Item_Card").offsetWidth + 50 >= _width);
            } else {
                if (ItemCardDisplay.length > 0) {
                    var len = ItemCardDisplay.length;
                    var _obj = ItemCardDisplay[len - 1];
                    var model = Class_ItemCard_ListNew.GetOfByItemCardCode(_obj.id);
                    if (_width - _itemcount >= 190) {
                        do {
                            model.ItemType = 0;
                            ItemCardDisplay.splice(len - 1, 1);
                            len = ItemCardDisplay.length;
                            this.Object$("Item_Card").innerHTML += "<SPAN class=comtabl id=" + model.ItemCardCode + " title=" + model.ItemModelDescribe + " onclick='Class_ItemCard_OprnNew.SelectItemCard(this);'><SPAN class=comtabr>" + model.FormatModelName() + "</SPAN></SPAN>";
                            if (len == 0) {
                                card_list.style.display = "none";
                                break;
                            };
                            _obj = ItemCardDisplay[len - 1];
                            model = Class_ItemCard_ListNew.GetOfByItemCardCode(_obj.id);
                        } while (_width - this.Object$("Item_Card").offsetWidth - 50 >= this.Object$(model.ItemCardCode).offsetWidth)
                    }
                }
            }
        } catch (e) { }
    }
};

function f_lefttdinout(str) {
    var _tbleft = document.all.tdleft;
    if (_tbleft.style.display == "none") {
        _tbleft.style.display = ""; str.title = "显示菜单";
    } else {
        _tbleft.style.display = "none"; str.title = "隐藏菜单";
    }
};

function f_toptrinout(str) {
    var _toptr = document.all.trtop;
    if (_toptr.style.display == "none") {
        _toptr.style.display = ""; str.title = "显示顶页";
    } else {
        _toptr.style.display = "none"; str.title = "隐藏菜单";
    }
};

function mouseOver(id) {
    imgaddress = "";
    if (id == "imgmenu") {
        var tbleft = document.all.tdleft;
        if (tbleft.style.display == "none")
            imgaddress = "../App_Themes/" + top.SystemSkinName + "/Images/img_menu_close_over.jpg";
        else
            imgaddress = "../App_Themes/" + top.SystemSkinName + "/Images/img_menu_open_over.jpg";
    } else if (id == "imgtop") {
        var toptr = document.all.trtop;
        if (toptr.style.display == "none")
            imgaddress = "../App_Themes/" + top.SystemSkinName + "/Images/img_dingye_close_over.jpg";
        else
            imgaddress = "../App_Themes/" + top.SystemSkinName + "/Images/img_dingye_open_over.jpg";
    }
    else
        imgaddress = "../App_Themes/" + top.SystemSkinName + "/Images/button_close_open.gif";
    document.getElementById(id).src = imgaddress;
};

function mouseOut(id) {
    imgaddress = ""; if (id == "imgmenu") {
        var tbleft = document.all.tdleft;
        if (tbleft.style.display == "none")
            imgaddress = "../App_Themes/" + top.SystemSkinName + "/Images/img_menu_close1.jpg";
        else
            imgaddress = "../App_Themes/" + top.SystemSkinName + "/Images/img_menu_open.jpg";
    }
    else if (id == "imgtop") {
        var toptr = document.all.trtop;
        if (toptr.style.display == "none")
            imgaddress = "../App_Themes/" + top.SystemSkinName + "/Images/img_dingye_close1.jpg";
        else
            imgaddress = "../App_Themes/" + top.SystemSkinName + "/Images/img_dingye_open.jpg";
    }
    else
        imgaddress = "../App_Themes/" + top.SystemSkinName + "/Images/button_close_close.gif"; document.getElementById(id).src = imgaddress;
};

(function () {
    //重构部分ICard
    window.ICard = Class_ItemCard_OprnNew;
    window.ICard.ListNew = Class_ItemCard_ListNew;
    var _NewId = 0;
    //获取或者设置当前窗体自增ID
    window.ICard.NewId = function (value) {
        var that = window.ICard;
        if (value != undefined) {
            _NewId = parseInt(value.split("M")[1]);
            return;
        }
        _NewId++;
        return "M" + _NewId;
    }
    //加载栏
    window.ICard.Loading = function (value) {
        var dom = $("#load");
        if (value == undefined) {
            if (dom.is(':hidden')) {
                return false;
            }
            return true;
        }
        if (value) {
            dom.show();
        }
        else {
            dom.hide();
        }
    }
    //打开新子窗体
    window.ICard.Open = function (option, title) {
        var that = window.ICard;
        that.Loading(true);
        if (typeof option == "string") {
            if (title == undefined) {
                title = null;
            }
            //查询有没有URL相同的子窗体
            var count = that.ListNew.GetCount();
            for (var i = 0; i < count; i++) {
                var model = that.ListNew.GetOfByItemCardIndex(i);
                model.IframeId = "Card_ifr_" + model.ItemCardCode.split("Card_")[1];
                model.Url = $("#" + model.IframeId).attr("src");
                if (model.ItemUrl.toLowerCase() == option.toLowerCase()) {
                    //刷新页面
                    that.OverlayItemCard(model.ItemModelCode, title, option, '0')
                    that.Loading(false);
                    console.log(model);
                    return;
                }
            }
            that.Create_ItemCard(that.NewId(), title, option, '0');
        }
    }
}());